package com.whiteape.book.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import com.gyf.immersionbar.ImmersionBar;
import com.umeng.analytics.MobclickAgent;
import com.whiteape.book.R;
import com.whiteape.book.WaApp;
import com.whiteape.book.ui.activity.MainActivity;
import com.whiteape.book.ui.activity.SearchActivity;
import com.whiteape.book.ui.base.BaseTabFragment;
import com.whiteape.book.utils.ShareUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

public class RecommendFragment extends BaseTabFragment {


//    @BindView(R.id.card_search)
//    CardView cardSearch;
//    @BindView(R.id.iv_share)
//    ImageView ivShare;
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @BindView(R.id.iv_back)
    ImageView ivBack;

    @Override
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
//                .fitsSystemWindows(true)  //使用该属性,必须指定状态栏颜色
                .statusBarDarkFont(true)
                .statusBarColor(R.color.colorPrimary)
                .init();
    }

    @Override
    protected int getContentId() {
        return R.layout.fragment_recommend;
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        ivBack.setOnClickListener(v -> {
            if (getActivity() != null) {
                getActivity().finish();
            }
        });
    }

    @Override
    protected List<Fragment> createTabFragments() {
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(RecommendChildFragment.newInstance(getString(R.string.sex_male)));
        fragmentList.add(RecommendChildFragment.newInstance(getString(R.string.sex_female)));

        return fragmentList;
    }

    @Override
    protected List<String> createTabTitles() {
        return Arrays.asList(getString(R.string.category_male), getString(R.string.category_female));
    }


    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);

        setHasOptionsMenu(true);
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
        if (((AppCompatActivity) getActivity()).getSupportActionBar() != null) {
            ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
            ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("搜书大全");
        }

        mTlIndicator.setSelectedTabIndicatorColor(WaApp.getInstance().getResources().getColor(R.color.colorAccent));
//        mTlIndicator.setTabTextColors(ColorUtil.isColorLight(ThemeStore.primaryColor(WaApp.getInstance().getApplicationContext())) ? Color.BLACK : Color.WHITE,
//                ThemeStore.accentColor(MApplication.getInstance().getApplicationContext()));
//        cardSearch.setOnClickListener(view -> {
//            MobclickAgent.onEvent(getContext(), "recf_search");
//            startActivityByAnim(new Intent(getContext(), SearchActivity.class),
//                    cardSearch, "sharedView", android.R.anim.fade_in, android.R.anim.fade_out);
//        });
//        ivShare.setOnClickListener(view -> {
//
//            MobclickAgent.onEvent(getContext(), "recf_share");
//            ShareUtil.checkPermissionAndShareInFragment(this, (MainActivity)getActivity());
////            checkPermissionAndShare();
////            ShareUtil.umShare(getActivity(), ((MainActivity) getActivity()));
//        });
        if (getActivity() != null && getActivity().getTheme() != null) {
            VectorDrawableCompat vectorDrawableCompat = VectorDrawableCompat.create(getResources(),
                    R.drawable.ic_share1, getActivity().getTheme());
            if (vectorDrawableCompat != null) {
                vectorDrawableCompat.setTint(getResources().getColor(R.color.share_btn_bg));
//                ivShare.setImageDrawable(vectorDrawableCompat);
            }
        }
    }


    //    @Override
//    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);
//    }

//    @Override
//    protected void bindView() {
//        unbinder = ButterKnife.bind(this, view);
//        super.bindView();
//    }
//
//    @Override
//    public void onDestroyView() {
//        super.onDestroyView();
//        unbinder.unbind();
//    }


}
